<template>
    <div class="app-container">
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo0" ref="enterpriseInfo0Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="账号信息" class="item-bottom" prop="userid">
                        <el-select v-model.number="enterpriseInfo0.userid" class="selectUser" :disabled="false">
                            <el-option v-for="item in noEnterpriseUserList" :key="item.userid" :label="item.username" :value="item.userid">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业网址" prop="website">
                        <el-input class="plainInput" v-model="enterpriseInfo0.website" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo1" ref="enterpriseInfo1Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业名称" prop="enterprisename">
                        <el-input class="plainInput" v-model="enterpriseInfo1.enterprisename" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="验证码数" prop="fakenumber" class="is-required">
                        <el-input class="plainInput" type="number" v-model="enterpriseInfo1.fakenumber" :maxlength="4"></el-input>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo2" ref="enterpriseInfo2Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="联系方式" prop="enterprisephone">
                        <el-input class="plainInput" v-model="enterpriseInfo2.enterprisephone" :maxlength="11"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="8">
                    <el-form-item label="企业法人" prop="owner">
                        <el-input class="plainInput" v-model="enterpriseInfo2.owner" :maxlength="50"></el-input>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo3" ref="enterpriseInfo3Form" :rules="rules">
                <el-col :xs="24" :sm="24" :md="24" :lg="20">
                    <el-form-item label="法定地址" prop="address">
                        <el-select v-model="enterpriseInfo3.addressPosition.province" placeholder="请选择省" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo3.addressPosition.provinceList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo3.addressPosition.city" placeholder="请选择市" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo3.addressPosition.cityList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo3.addressPosition.county" placeholder="请选择县" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo3.addressPosition.countyList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo3.addressPosition.town" placeholder="请选择镇" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo3.addressPosition.townList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-input class="detailAddr" v-model="enterpriseInfo3.address" prop="address"></el-input>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo4" ref="enterpriseInfo4Form" :rules="rules">
                <el-col :xs="24" :sm="24" :md="24" :lg="20">
                    <el-form-item label="生产地址" prop="productionAddr">
                        <el-select v-model="enterpriseInfo4.productionPosition.province" placeholder="请选择省" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo4.productionPosition.provinceList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo4.productionPosition.city" placeholder="请选择市" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo4.productionPosition.cityList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo4.productionPosition.county" placeholder="请选择县" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo4.productionPosition.countyList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-select v-model="enterpriseInfo4.productionPosition.town" placeholder="请选择镇" class="selectOther" :disabled="false">
                            <el-option v-for="item in enterpriseInfo4.productionPosition.townList" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                        <el-input class="detailAddr" v-model="enterpriseInfo4.productionAddr"></el-input>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo5" ref="enterpriseInfo5Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="经营范围" prop="enterprisescope">
                        <el-input type="textarea" :rows="8" class="bussinessScope" v-model="enterpriseInfo5.scope" :maxlength="1024"></el-input>
                    </el-form-item>
                    <p class="textLenTips">
                        <el-form-item class="imgTipsItem">
                        {{ scopeTextLenTips ||'最多可录入1024个字符'}}
                    </el-form-item>
                    </p> 
                </el-col>
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="营业执照">
                        <div class="businessLicense">
                            <el-upload class="avatar-uploader" :action="uploadUrl" :show-file-list="false" :on-success="handleLicenseSuccess" :before-upload="beforeAvatarUpload">
                                <img v-if="imageUrlLicense" :src="imageUrlLicense" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </div>
                    </el-form-item>
                    <p class="imgTips">
                        <el-form-item class="imgTipsItem">图片大小限制为2M,类型支持jpeg、png格式</el-form-item>
                    </p> 
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo6" ref="enterpriseInfo6Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="服务信息" prop="serviceinformation">
                        <el-input type="textarea" :rows="8" class="bussinessScope" v-model="enterpriseInfo6.serviceinformation" :maxlength="1024"></el-input>
                    </el-form-item>
                    <p class="textLenTips">
                        <el-form-item class="imgTipsItem">
                        {{ serviceTextLenTips ||'最多可录入1024个字符'}}
                        </el-form-item>
                    </p> 
                </el-col>
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="企业logo">
                        <div class="businessLicense">
                            <el-upload class="avatar-uploader" :action="uploadUrl" :show-file-list="false" :on-success="handleLogoSuccess" :before-upload="beforeAvatarUpload">
                                <img v-if="imageUrlLogo" :src="imageUrlLogo" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </div>
                    </el-form-item>
                    <p  class="imgTips">
                      <el-form-item class="imgTipsItem">图片大小限制为2M,类型支持jpeg、png格式</el-form-item>
                    </p> 
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-form :inline="true" :model="enterpriseInfo7" ref="enterpriseInfo7Form" :rules="rules">
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="公司简介" prop="enterpriseprofile">
                        <el-input type="textarea" :rows="8" class="bussinessScope" v-model="enterpriseInfo7.enterpriseprofile" :maxlength="1024"></el-input>
                    </el-form-item>
                    <p  class="textLenTips">
                        <el-form-item class="imgTipsItem">
                            {{ profileTextLenTips || '最多可录入1024个字符'}}
                        </el-form-item>
                    </p>
                </el-col>
                <el-col :xs="24" :sm="12" :md="8" :lg="8">
                    <el-form-item label="宣传视频">
                        <div class="businessLicense">
                            <el-upload class="avatar-uploader" :action="uploadUrl" :show-file-list="false" :on-success="handleVideoSuccess" :before-upload="beforeVideoUpload">
                                <!-- <img v-if="imageUrlVideo" :src="imageUrlVideo" class="avatar"> -->
                                <video v-if="imageUrlVideo" :src="imageUrlVideo" autoplay="autoplay" controls="controls" class="vediocss">
                                    您的浏览器不支持 video 标签
                                </video>
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </div>
                    </el-form-item>
                    <p class="imgTips">
                        <el-form-item class="imgTipsItem">视频大小限制为20M,类型支持MP4格式</el-form-item>
                    </p>
                </el-col>
            </el-form>
        </el-row>
        <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="8">
                <div class='tips'>&nbsp;&nbsp;{{tips}}</div>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8">
                <div class="operateBtn">
                    <el-button @click="saveEnterprise"><icon-svg icon-class="baocun1"></icon-svg>&nbsp;&nbsp;保存</el-button>
                    <el-button @click="cancel"><icon-svg icon-class="quxiao"></icon-svg>&nbsp;&nbsp;取消</el-button>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<style scoped>
.selectOther {
    width: 130px;
}

.selectUser {
    width: 250px;
}

.detailAddr {
    width: 155px;
}

.plainInput {
    width: 250px;
}

.bussinessScope {
    width: 250px;
    overflow: auto;
    word-break: break-all;
}

.businessLicense {
    width: 256px;
    height: 180px;
    border: 1px dashed #d9d9d9;
}

.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 250px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 253px;
    height: 178px;
    display: block;
}

.operateBtn {
    text-align: center;
    margin: 0 auto;
}

.tips {
    font-size: 14px;
    color: red;
}

.vediocss {
    background-color: black;
    height: 178px;
    width: 250px;
}

.textLenTips {
    margin-top: -20px;
    margin-left: 65px;
    color: #bfcbd9;
    margin-bottom: 0px;
}

.imgTips {
    margin-top: -20px;
    margin-left: 67px;
    color: #bfcbd9;
}

.imgTipsItem {
    margin-bottom: 0px;
}

</style>

<script>
import { getNoEnterpriseUserList, updateEnterpriseInfo } from 'api/enterprise';
import { getPositionList } from 'api/system';
import { validateURL, validateTelno, validateFakeno } from 'utils/validate';
import Cookies from 'js-cookie';

export default {
    data() {
        // 效验防伪码数量
        const checkFakeNumber = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('验证码数量不能为空'));
            }
            if (!validateFakeno(value)) {
                callback(new Error('允许数值范围为:1~9999'));
            } else {
                callback();
            }
        };
        // 效验企业网址
        const checkWebSite = (rule, value, callback) => {
            if (!validateURL(value) && value != '') {
                callback(new Error('请输入正确的网址'));
            } else {
                callback();
            }
        };

        // 效验联系电话
        const checkTelno = (rule, value, callback) => {
            if (!validateTelno(value) && value != '') {
                callback(new Error('请输入正确的手机号'));
            } else {
                callback();
            }
        };

        // 验证企业地址
        const checkAddr = (rule, value, callback) => {
            // setTimeout(() => {
            //     let v = value.length;
            //     if ((v < 0 || v > 40) && value != '') {
            //         callback(new Error('允许字符个数为:1~40'));
            //     } else {
            //         callback();
            //     }
            // }, 300);
            let v = value.length;
            if ((v < 0 || v > 100) && value != '') {
                callback(new Error('允许字符个数为:1~100'));
            } else {
                callback();
            }
        };

        // 效验企业用户
        const checkUserId = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('请选择一个企业用户'));
            } else {
                callback();
            }
        }

        return {
            enterpriseInfo7: {
                enterpriseprofile: '',
                video: ''
            },
            enterpriseInfo6: {
                serviceinformation: '',
                logo: ''
            },
            enterpriseInfo5: {
                scope: '',
                businesslicense: ''
            },
            enterpriseInfo4: {
                productionaddressid: '',
                productionAddr: '',
                productionPosition: {
                  province: '',
                  city: '',
                  county: '',
                  town: '',
                  provinceList: null,
                  cityList: null,
                  countyList: null,
                  townList: null
                },                
                changeFlag: false
            },
            enterpriseInfo3: {
                addressid: '',
                address: '',
                addressPosition: {
                  province: '',
                  city: '',
                  county: '',
                  town: '',
                  provinceList: null,
                  cityList: null,
                  countyList: null,
                  townList: null      
                }, 
                changeFlag: false
            },
            enterpriseInfo2: {
                enterprisephone: '',
                owner: ''
            },
            enterpriseInfo1: {
                enterpriseid: null,
                enterprisename: '',
                fakenumber: 0
            },
            enterpriseInfo0: {
                userid: null,
                username: '',
                userType: '',
                website: ''
            },
            imageUrlLicense: '',
            imageUrlLogo: '',
            imageUrlVideo: '',
            tips: '',           
            productType: [],
            positionCode: null,
            noEnterpriseUserList: [],
            uploadUrl: '',
            rules: {
                userid: [{ validator: checkUserId, trigger: 'blur' }],
                enterprisename: [{ required: true, message: '请输入企业名称', trigger: 'blur' },
                { min: 0, max: 40, message: '长度在 1 到 40 个字符', trigger: 'blur' }],
                fakenumber: [{ required: true, message: '请输入验证码数量', trigger: 'blur' },{ validator: checkFakeNumber, trigger: 'blur' }],
                website: [{ validator: checkWebSite, trigger: 'blur' }],
                enterprisephone: [{ validator: checkTelno, trigger: 'blur' }],
                owner: [{ min: 0, max: 40, message: '长度在 0 到 40 个字符', trigger: 'blur' }],
                address: [{ validator: checkAddr, trigger: 'blur' }],
                productionAddr: [{ validator: checkAddr, trigger: 'blur' }],
                serviceinformation: [{ min: 0, max: 1024, message: '长度在 0 到 1024 个字符', trigger: 'blur' }],
                enterprisescope: [{ min: 0, max: 1024, message: '长度在 0 到 1024 个字符', trigger: 'blur' }],
                enterpriseprofile: [{ min: 0, max: 1024, message: '长度在 0 到 1024 个字符', trigger: 'blur' }],
            },
            form0Valid: false,
            form1Valid: false,
            form2Valid: false,
            form3Valid: true,
            form4Valid: true,
            form5Valid: true,
            form6Valid: true,
            form7Valid: true,
            uploadUrl: 'trc-service-enterprise/enterprise/fileservice/upload?operatorid=' + Cookies.get('uid') + '&lastlogincode=' + Cookies.get('lastlogincode'),
            scopeTextLenTips: '',
            serviceTextLenTips: '',
            profileTextLenTips: ''
        }
    },   
    watch: {
        ['enterpriseInfo3.addressPosition.province'](newVal,oldVal) { 
          if (oldVal || this.enterpriseInfo3.changeFlag ) {
             this.getPosition(2,this.enterpriseInfo3.addressPosition);
             this.enterpriseInfo3.addressPosition.city = '';
             this.enterpriseInfo3.addressPosition.cityList = '';
             this.enterpriseInfo3.addressPosition.county = '';
             this.enterpriseInfo3.addressPosition.countyList = '';
             this.enterpriseInfo3.addressPosition.town = '';
             this.enterpriseInfo3.addressPosition.townList = '';
             this.enterpriseInfo3.changeFlag = true;
           }            
        },
        ['enterpriseInfo3.addressPosition.city'](newVal,oldVal) {
          if (oldVal || this.enterpriseInfo3.changeFlag) {
             this.getPosition(3,this.enterpriseInfo3.addressPosition); 
             this.enterpriseInfo3.addressPosition.county = '';
             this.enterpriseInfo3.addressPosition.countyList = '';
             this.enterpriseInfo3.addressPosition.town = '';
             this.enterpriseInfo3.addressPosition.townList = '';
             this.enterpriseInfo3.changeFlag = true;
          }            
        },
        ['enterpriseInfo3.addressPosition.county'](newVal,oldVal) {
           if (oldVal || this.enterpriseInfo3.changeFlag) { 
             this.getPosition(4,this.enterpriseInfo3.addressPosition);
             this.enterpriseInfo3.addressPosition.town = '';
             this.enterpriseInfo3.addressPosition.townList = '';
             this.enterpriseInfo3.changeFlag = true;
           }
        },
       ['enterpriseInfo4.productionPosition.province'](newVal,oldVal) {
           if (oldVal || this.enterpriseInfo4.changeFlag) {
             this.getPosition(2,this.enterpriseInfo4.productionPosition);
             this.enterpriseInfo4.productionPosition.city = '';
             this.enterpriseInfo4.productionPosition.county = '';
             this.enterpriseInfo4.productionPosition.town = '';
             this.enterpriseInfo4.changeFlag = true;
           }           
        },
        ['enterpriseInfo4.productionPosition.city'](newVal,oldVal) {
           if (oldVal || this.enterpriseInfo4.changeFlag) {
            this.getPosition(3,this.enterpriseInfo4.productionPosition); 
            this.enterpriseInfo4.productionPosition.county = '';
            this.enterpriseInfo4.productionPosition.town = '';
            this.enterpriseInfo4.changeFlag = true;
           }    
        },
        ['enterpriseInfo4.productionPosition.county'](newVal,oldVal) {
            if (oldVal || this.enterpriseInfo4.changeFlag) {
              this.getPosition(4,this.enterpriseInfo4.productionPosition);
              this.enterpriseInfo4.productionPosition.town = '';
              this.enterpriseInfo4.changeFlag = true;
            }            
        },
        'enterpriseInfo5.scope': function(val) {
            this.scopeTextLenTips = val.length + ' / 1024'
        },
        'enterpriseInfo6.serviceinformation': function(val) {
            this.serviceTextLenTips = val.length + ' / 1024'
        },
        'enterpriseInfo7.enterpriseprofile': function(val) {
            this.profileTextLenTips = val.length + ' / 1024'
        }        
    },
    computed: {
        checkValidFlag: function () {
            return this.form0Valid && this.form1Valid && this.form2Valid && this.form3Valid
                 && this.form4Valid && this.form5Valid && this.form6Valid && this.form7Valid
        }
    },
    created() {
        // 表单初始化
        let enterprise = this.$route.query.enterpriseinfo; 
        let addressPosition = this.$route.query.addressPosition;
        let productPosition = this.$route.query.productPosition;    
        this.enterpriseInfo7.enterpriseprofile = enterprise.enterpriseprofile || '';
        this.enterpriseInfo7.video = enterprise.video || '';
        this.imageUrlVideo = enterprise.videoURL || '';
        this.enterpriseInfo6.serviceinformation = enterprise.serviceinformation || '';
        this.enterpriseInfo6.logo = enterprise.logo || '';
        this.imageUrlLogo = enterprise.logoURL || '';
        this.enterpriseInfo5.scope = enterprise.scope || '';
        this.imageUrlLicense = enterprise.businesslicenseURL || '';
        this.enterpriseInfo5.businesslicense = enterprise.businesslicense || '';
        this.enterpriseInfo4.productionaddressid = enterprise.productionaddressid || '';
        this.enterpriseInfo4.productionAddr = enterprise.productionaddress || '';
        this.enterpriseInfo4.productionPosition = productPosition;        
        this.enterpriseInfo3.addressid = enterprise.addressid || '';
        this.enterpriseInfo3.address = enterprise.address || '';
        this.enterpriseInfo3.addressPosition = addressPosition;
        this.enterpriseInfo2.enterprisephone = enterprise.enterprisephone || '';
        this.enterpriseInfo2.owner = enterprise.owner || '';
        this.enterpriseInfo1.enterpriseid = enterprise.enterpriseid || '';
        this.enterpriseInfo1.enterprisename = enterprise.enterprisename || '';
        this.enterpriseInfo1.fakenumber =  enterprise.fakenumber + '' || 0;
        this.enterpriseInfo0.userid = enterprise.userid || '';
        this.enterpriseInfo0.username = enterprise.username || '';
        this.enterpriseInfo0.userType = enterprise.userType || '';
        this.enterpriseInfo0.website = enterprise.website || '';
        if (!this.enterpriseInfo3.addressPosition.province) {
           this.getPosition(1,this.enterpriseInfo3.addressPosition);
           this.enterpriseInfo3.changeFlag = true;
        };
        if (!this.enterpriseInfo4.productionPosition.province) {
           this.getPosition(1,this.enterpriseInfo4.productionPosition);
           this.enterpriseInfo4.changeFlag = true;
        };
        this.getNoEnterpriseUser();
    },
    methods: {  
        getPosition(level,position) {
            let pisCode = null;
            switch (level) {
                case 1: pisCode = null; break;
                case 2: pisCode = position.province; break;
                case 3: pisCode = position.city; break;
                case 4: pisCode = position.county; break;
                default: break;
            };
            let parentcode = {
                parentcode: pisCode
            };
            getPositionList(parentcode).then(response => {
                let res = response.data;
                if (res.flag === 1) {
                    switch (level) {
                        case 1: position.provinceList = res.data; break;
                        case 2: position.cityList = res.data; break;
                        case 3: position.countyList = res.data; break;
                        case 4: position.townList = res.data; break;
                        default: break;
                    }
                }               
            })
        },        
        getNoEnterpriseUser() {
            // 初始化已选中的用户
            let userinfo = {
                userid: this.enterpriseInfo0.userid,
                username: this.enterpriseInfo0.username,
                usertype: ''
            }
            getNoEnterpriseUserList().then(response => {
                let res = response.data;
                if (res.flag === 1) {
                    this.noEnterpriseUserList = res.data;
                    this.noEnterpriseUserList.push(userinfo);
                    // for (let i=0; i<this.noEnterpriseUserList.length; i++) {
                    //     this.noEnterpriseUserList[i].userid = this.noEnterpriseUserList[i].userid + ''
                    // }                    
                } else {
                    console.log('查询无关联企业用户失败.');
                }
            })
        },
        saveEnterprise() {
            let enterprise = {
                userid: this.enterpriseInfo0.userid || '',
                enterpriseid: this.enterpriseInfo1.enterpriseid || '',
                enterprisename: this.enterpriseInfo1.enterprisename || '',
                fakenumber: this.enterpriseInfo1.fakenumber || 0,
                enterprisephone: this.enterpriseInfo2.enterprisephone || '',
                owner: this.enterpriseInfo2.owner || '',
                addressid: this.enterpriseInfo3.addressPosition.town || this.enterpriseInfo3.addressPosition.county || this.enterpriseInfo3.addressPosition.city || this.enterpriseInfo3.addressPosition.province || '',
                address: this.enterpriseInfo3.address || '',
                productionaddressid: this.enterpriseInfo4.productionPosition.town || this.enterpriseInfo4.productionPosition.county || this.enterpriseInfo4.productionPosition.city || this.enterpriseInfo4.productionPosition.province || '',
                productionaddress: this.enterpriseInfo4.productionAddr || '',
                scope: this.enterpriseInfo5.scope || '',
                businesslicenseURL: this.imageUrlLicense || '',
                serviceinformation: this.enterpriseInfo6.serviceinformation || '',
                logoURL: this.imageUrlLogo || '',
                enterpriseprofile: this.enterpriseInfo7.enterpriseprofile || '',
                videoURL: this.imageUrlVideo || '',
                website: this.enterpriseInfo0.website || ''
            }

            this.$refs['enterpriseInfo0Form'].validate(valid => {
                if (valid) {
                    // form0效验成功                    
                    this.form0Valid = true
                } else {
                    console.log('form0效验失败.');
                    this.form0Valid = false
                }
            });

            this.$refs['enterpriseInfo1Form'].validate(valid => {
                if (valid) {
                    // form1效验成功                    
                    this.form1Valid = true
                } else {
                    console.log('form1效验失败.');
                    this.form1Valid = false
                }
            });

            this.$refs['enterpriseInfo2Form'].validate(valid => {
                if (valid) {
                    // form2效验成功                    
                    this.form2Valid = true
                } else {
                    console.log('form2效验失败.');
                    this.form2Valid = false
                }
            });

            this.$refs['enterpriseInfo3Form'].validate(valid => {
                if (valid) {
                    // form3效验成功                    
                    this.form3Valid = true
                } else {
                    console.log('form3效验失败.');
                    this.form3Valid = false
                }
            });

            this.$refs['enterpriseInfo4Form'].validate(valid => {
                if (valid) {
                    // form4效验成功                    
                    this.form4Valid = true
                } else {
                    console.log('form4效验失败.');
                    this.form4Valid = false
                }
            });

            this.$refs['enterpriseInfo5Form'].validate(valid => {
                if (valid) {
                    // form5效验成功                    
                    this.form5Valid = true
                } else {
                    console.log('form5效验失败.');
                    this.form5Valid = false
                }
            });


            this.$refs['enterpriseInfo6Form'].validate(valid => {
                if (valid) {
                    // form6效验成功                    
                    this.form6Valid = true
                } else {
                    console.log('form6效验失败.');
                    this.form6Valid = false
                }
            });

            this.$refs['enterpriseInfo7Form'].validate(valid => {
                if (valid) {
                    // form6效验成功                    
                    this.form7Valid = true
                } else {
                    console.log('form7效验失败.');
                    this.form7Valid = false
                }
            });

            if (this.checkValidFlag) {
                updateEnterpriseInfo(enterprise).then(response => {
                    let res = response.data;
                    if (res.flag === 1) {
                        this.tips = '企业信息新建成功';
                        this.$router.go(-1);
                    } else {
                        this.tips = '企业信息保存失败'
                    }
                })
            }
        },
        cancel() {
            this.$router.go(-1)
        },
        handleLicenseSuccess(res, file) {
            if (res.flag === 1) {
                this.enterpriseInfo5.businessLicense = res.data[0];
                this.imageUrlLicense = res.data[0];
            } else {
                console.log(res.message);
            }
            // this.imageUrl = URL.createObjectURL(file.raw);
        },
        handleLogoSuccess(res, file) {
            if (res.flag === 1) {
                this.enterpriseInfo6.logo = res.data[0];
                this.imageUrlLogo = res.data[0];
            } else {
                console.log(res.message);
            }
            // this.imageUrl = URL.createObjectURL(file.raw);
        },
        handleVideoSuccess(res, file) {
            if (res.flag === 1) {
                this.enterpriseInfo7.video = res.data[0];
                this.imageUrlVideo = res.data[0];
            } else {
                console.log(res.message);
            }
            // this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {            
            const isJPG = (file.type === 'image/jpeg') || (file.type === 'image/png') ;
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
                this.$message.error('上传图片只能是jpeg、png格式');
            }
            if (!isLt2M) {
                this.$message.error('上传图片大小不能超过2MB');
            }
            return isJPG && isLt2M;
        },
        beforeVideoUpload(file) {
            const isMP4 = file.type === 'video/mp4';
            const isLt20M = file.size / 1024 / 1024 < 20;

            if (!isMP4) {
                this.$message.error('上传视频只能是MP4格式');
            }
            if (!isLt20M) {
                this.$message.error('上传视频大小不能超过20MB');
            }
            return isMP4 && isLt20M;
        }
    }
};
</script>